﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace ParserGenerator.ParserConstruction
{
    [Serializable]
    public sealed class ParserAutomatonActionsTable : ReadOnlyDictionary<ParserAutomatonState, ParserAutomatonActions>
    {
        internal ParserAutomatonActionsTable(ParserAutomatonStateTable states)
            : base(new Dictionary<ParserAutomatonState, ParserAutomatonActions>())
        {
            if (states == null)
                throw new ArgumentNullException(nameof(states));
            foreach (ParserAutomatonState state in states)
            {
                var lookaheadSets = state.IsConsistent ? null : states.ReductionLookaheadSets[state];
                var actions = new ParserAutomatonActions(state, lookaheadSets);
                Dictionary.Add(state, actions);
            }
        }
    }
}
